package yjh.mapper;

import org.apache.ibatis.annotations.*;
import yjh.pojo.TopicTable;

import java.util.List;

@Mapper
public interface TopicTableMapper {

    /**
     * 新增题目 TODO
     * @param id
     * @param topic
     * @param answer
     * @param importanc
     * @return
     */
    @Insert("INSERT INTO topictable (id, topic, answer, importanc) VALUES (#{id},#{topic},#{answer},#{importanc})")
    public boolean insertTopicTable(@Param("id") Integer id,
                                    @Param("topic") String topic,
                                    @Param("answer") String answer,
                                    @Param("importanc") int importanc);

    /**
     * 删除题目
     * @param topic
     * @return
     */
    @Delete("DELETE FROM topictable WHERE topic = #{topic}")
    public boolean deleteTopicTable(@Param("topic") String topic);

    /**
     * 修改更新题目
     * @param afterChangeTopic
     * @param answer
     * @param importanc
     * @param beforeChangeTopic
     * @return
     */
    public boolean updateTopicTable(@Param("afterChangeTopic") String afterChangeTopic,
                                    @Param("answer") String answer,
                                    @Param("importanc") Integer importanc,
                                    @Param("beforeChangeTopic")String beforeChangeTopic);

    /**
     * 根据题目查询
     * @param topic
     * @return
     */
    @Select("SELECT * FROM topictable WHERE topic=#{topic}")
    public TopicTable selectTopicTableOneByTopic(@Param("topic") String topic);

    /**
     * 查询所有
     * @return
     */
    @Select("SELECT * FROM topictable")
    public List<TopicTable> selectTopicTableAll();

    /**
     * 查询题目总数
     * @return
     */
    @Select("SELECT count(*) FROM topictable")
    public int selectTopicTableCount();

    /**
     * 查询个数
     * @param importanc
     * @return
     */
    @Select("SELECT count(*) FROM topictable WHERE importanc=#{importanc}")
    public int selectTopicTableCountByImportanc(@Param("importanc") int importanc);

    /**
     * 通过重要度查询题目
     * @param importanc
     * @return
     */
    @Select("SELECT * FROM topictable WHERE importanc=#{importanc}")
    public List<TopicTable> selectTopicTableByImportanc(@Param("importanc") int importanc);

    /**
     * 通过id查询题目信息
     */
    @Select("SELECT * FROM topictable WHERE id=#{tid}")
    public TopicTable selectTopicTableById(@Param("tid") int tid);

    /**
     * 通过id和重要度查询题目信息
     */
    @Select("SELECT * FROM topictable WHERE id=#{tid} and importanc=#{importanc}")
    public TopicTable selectTopicTableByIdAndImportanc(@Param("tid") int tid,
                                                       @Param("importanc") int importanc);

    /**
     * 添加mid
     * @param mid
     * @return
     */
    @Update("UPDATE topictable SET mid = #{mid} WHERE id = #{tid} and mid = null")
    public int updateMid(@Param("mid") int mid,@Param("tid") int tid);
}
